package so.shanku.essential.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.nostra13.universalimageloader.core.ImageLoader;
import net.tsz.afinal.json.JsonMap;
import so.shanku.essential.R;
import so.shanku.essential.app.MyApplication;
import so.shanku.essential.utils.ImageLoaderBitmapCallBack;

import java.util.List;
import java.util.Map;

/**
 * Created by Jaelyn on 2015/9/7.
 */
public class ProductCategoryAdapter extends MyBaseAdapter {

	//private ItemAttentionChange attentionChange;

	public ProductCategoryAdapter(Context context, List<? extends Map<String, ?>> datas) {
		super(context, datas);
		//this.attentionChange = callback2;
	}


	@Override
	public View getView(final int position, View view, ViewGroup viewGroup) {
        GoodsCategoryAdapterViewHolder goodsCategoryAdapterViewHolder;
		if (view == null) {
			view = layoutInflater.inflate(R.layout.goods_classfy_item, viewGroup, false);
            goodsCategoryAdapterViewHolder = new GoodsCategoryAdapterViewHolder(view);
			view.setTag(goodsCategoryAdapterViewHolder);
		} else {
            goodsCategoryAdapterViewHolder = (GoodsCategoryAdapterViewHolder) view.getTag();
		}
		 JsonMap data = (JsonMap) datas.get(position);      //brandLog
        goodsCategoryAdapterViewHolder.classfy_name_tv.setText(data.getStringNoNull("categoryName"));
        goodsCategoryAdapterViewHolder.classfy_name_tv.setTextColor(Color.parseColor("#"+data.getStringNoNull("textColor","ffffff")));

		String picPath = data.getStringNoNull("picPath");
		if (MyApplication.getInstance().getBitmapHashMap().containsKey(picPath)) {
            goodsCategoryAdapterViewHolder.classfy_logo_iv.setImageBitmap((MyApplication.getInstance().getBitmapHashMap().get(picPath)));
		} else {
			ImageLoader.getInstance().displayImage(picPath,goodsCategoryAdapterViewHolder.classfy_logo_iv, MyApplication.getInstance().getBrandDefaultOption(), new ImageLoaderBitmapCallBack());
		}

		return view;
	}

	private  class GoodsCategoryAdapterViewHolder {
		@ViewInject(R.id.classfy_logo_iv)
		private ImageView classfy_logo_iv;
		@ViewInject(R.id.classfy_name_tv)
		private TextView classfy_name_tv;

		public GoodsCategoryAdapterViewHolder(View view) {
			ViewUtils.inject(this, view);
		}
	}

}
